#! /bin/sh
#
# halt		Execute the halt command.
#
# Version:      @(#)halt  2.85-22  19-Jun-2004  miquels@cistron.nl
#
exit 0

PATH=/sbin:/bin:/usr/sbin:/usr/bin

# Get the default from /etc/default/halt.
[ -f /etc/default/halt ] && . /etc/default/halt

if [ "$INIT_HALT" = "" ]
then
	case "$HALT" in
		[Pp]*)
			INIT_HALT=POWEROFF
			;;
		[Hh]*)
			INIT_HALT=HALT
			;;
		*)
			INIT_HALT=POWEROFF
			;;
	esac
fi

# See if we need to cut the power.
if [ "$INIT_HALT" = "POWEROFF" ] && [ -x /etc/init.d/ups-monitor ]
then
	/etc/init.d/ups-monitor poweroff
fi

# Don't shut down drives if we're using RAID.
hddown="-h"
if grep -qs '^md.*active' /proc/mdstat
then
	hddown=""
fi

# If INIT_HALT=HALT don't poweroff.
poweroff="-p"
if [ "$INIT_HALT" = "HALT" ]
then
	poweroff=""
fi

halt -d -f -i $poweroff $hddown

: exit 0
